package IO;

import java.io.*;
import java.nio.charset.Charset;

public class FilterInputStreamTest {
    public static void main(String[] args) {
        try (
                //定义输出流
                OutputStream out = new FileOutputStream("/Users/zhang/Documents/doc/test.txt");
                //装饰输出流
                DataOutputStream dataOutputStream = new DataOutputStream(out);
                //定义输入流
                InputStream in = new FileInputStream("/Users/zhang/Documents/doc/test.txt");
                //装饰输入流
                DataInputStream dataInputStream = new DataInputStream(in)) {
            Charset cs = Charset.defaultCharset();
            System.out.println(cs);
            //使用装饰类写一个字符串
            dataOutputStream.writeUTF("你好,Java!");
            //注意:输出流和输入流,一一对应,写一次就需要读一次
            dataOutputStream.writeUTF("你好,Java!");
            //读取输入流内容并打印
            System.out.print(dataInputStream.readUTF());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
